package com.topboya.linker.ui.activity;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.topboya.linker.R;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.utils.DataCleanUtils;
import com.topboya.linker.utils.LogUtils;

public class SettingActivity extends BaseActivity {

    private static final String TAG = "SettingActivity:";
    private Toolbar toolbar;
    private TextView toolbar_title;
    private TextView tv_toolbar_right;
    private RelativeLayout rl_changeps;
    private RelativeLayout rl_bundwx;
    private RelativeLayout rl_aboutus;
    private RelativeLayout rl_clear;
    private RelativeLayout rl_update;
    private TextView tv_clear_size;
    private Button btn_exit;

    @Override
    protected int getLayoutId() {

        return R.layout.activity_setting;
    }

    @Override
    protected void initView() {

        toolbar = findViewById(R.id.toolbar);
        toolbar_title = findViewById(R.id.toolbar_title);
        tv_toolbar_right = findViewById(R.id.tv_toolbar_right);
        rl_changeps = findViewById(R.id.rl_changeps);
        rl_bundwx = findViewById(R.id.rl_bundwx);
        rl_aboutus = findViewById(R.id.rl_aboutus);
        rl_clear = findViewById(R.id.rl_clear);
        rl_update = findViewById(R.id.rl_update);
        btn_exit = findViewById(R.id.btn_exit);
        tv_clear_size = findViewById(R.id.tv_clear_size);
             initTitle();
    }

    private void initTitle() {

        toolbar_title.setText("设置");
        tv_toolbar_right.setVisibility(View.GONE);
        String size="0 M";
        try {
             size = DataCleanUtils.getTotalCacheSize(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        tv_clear_size.setText(size);

    }

    @Override
    protected void initData() {



    }

    @Override
    protected void initListener() {

        toolbar.setNavigationOnClickListener(v -> {finish();});
        rl_changeps.setOnClickListener(v -> { jumpToActivity(ChangepsActivity.class); });
        rl_aboutus.setOnClickListener(v -> { jumpToActivity(AboutUsActivity.class);});
        btn_exit.setOnClickListener(v -> {

            Intent intent = new Intent(this, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        });
        rl_clear.setOnClickListener(v -> {

            DataCleanUtils.clearAllCache(SettingActivity.this);

            String size="0 M";
            try {
                size = DataCleanUtils.getTotalCacheSize(this);
            } catch (Exception e) {
                e.printStackTrace();
            }
            tv_clear_size.setText(size);
        });
    }

    @Override
    protected BasePresenter createPresenter() {

        return null;
    }


}
